package hn.cch.kafka.runner;

import hn.cch.kafka.service.KafkaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.stereotype.Component;

@Component
public class KafkaApplicationRunner implements ApplicationRunner {

    private final static Logger logger = LoggerFactory.getLogger(KafkaApplicationRunner.class);


    @Autowired
    private KafkaService kafkaService;

    @Autowired
    private ConcurrentKafkaListenerContainerFactory<String, String> containerFactory;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        kafkaService.subscribe("topic-name");
        containerFactory.setAckDiscarded(Boolean.FALSE);
    }
}
